<?php

namespace app\common\jobs\notice;

use tmcore\services\QueueService;
use think\facade\Log;
use tmcore\base\BaseJob;
use tmcore\services\notice\wechat\WechatSendService;
use tmcore\traits\JobTrait;

/**
 * 发送微信模板消息
 */
class WechatTemplateJob extends BaseJob
{
    use JobTrait;

    public function doJob($data) {
        try {
            (new WechatSendService)->sendWechatTemplate($data['openid'], $data['templateId'], $data['templateParams'], $data['id']);
            return $this->success();
        } catch (\Exception $e) {
            return $this->error('执行任务失败,' . ' 行号：' . $e->getLine() . '文件：' . $e->getFile() . '错误信息：' . $e->getMessage());
        }
    }

    public function notify($data) {
        try {
            (new QueueService)->addQueueLog($data);
        } catch (\Exception $e) {
            Log::error('执行任务失败,' . ' 行号：' . $e->getLine() . '文件：' . $e->getFile() . '错误信息：' . $e->getMessage());
        }
    }
}